﻿namespace HZY.Repository.FreeSql.Admin.Repositories;

public interface IRepositoryBase<T> : IBaseRepository<T>, IScopedDependency where T : class
{
    #region 查询 单条数据

    /// <summary>
    /// 查询 根据id
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <param name="key"></param>
    /// <returns></returns>
    T FindById<TKey>(TKey key);

    /// <summary>
    /// 查询 根据id
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <param name="key"></param>
    /// <returns></returns>
    Task<T> FindByIdAsync<TKey>(TKey key);

    /// <summary>
    /// 查询 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    T Find(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 查询 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    Task<T> FindAsync(Expression<Func<T, bool>> expWhere);

    #endregion

    #region 查询 多条数据

    /// <summary>
    /// 获取所有数据
    /// </summary>
    /// <returns></returns>
    List<T> ToListAll();

    /// <summary>
    /// 获取所有数据
    /// </summary>
    /// <returns></returns>
    Task<List<T>> ToListAllAsync();


    /// <summary>
    /// 获取列表 根据查询条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    Task<List<T>> ToListAsync(Expression<Func<T, bool>> expWhere);

    #endregion

    #region 更新

    /// <summary>
    /// 根据实体id更新数据
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    Task<int> UpdateByIdAsync(T model);

    #endregion

    #region 删除

    /// <summary>
    /// 删除 根据id
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="TKey"></typeparam>
    /// <returns></returns>
    int DeleteById<TKey>(TKey key);

    /// <summary>
    /// 删除 根据 id集合
    /// </summary>
    /// <param name="keys"></param>
    /// <typeparam name="TKey"></typeparam>
    /// <returns></returns>
    int DeleteByIds<TKey>(IEnumerable<TKey> keys);


    /// <summary>
    /// 删除 根据 id
    /// </summary>
    /// <param name="key"></param>
    /// <typeparam name="TKey"></typeparam>
    /// <returns></returns>
    Task<int> DeleteByIdAsync<TKey>(TKey key);

    /// <summary>
    /// 删除 根据id集合
    /// </summary>
    /// <param name="keys"></param>
    /// <typeparam name="TKey"></typeparam>
    /// <returns></returns>
    Task<int> DeleteByIdsAsync<TKey>(IEnumerable<TKey> keys);

    #endregion

    #region 是否存在 、 数量


    /// <summary>
    /// 获取数量
    /// </summary>
    /// <returns></returns>
    int Count();

    /// <summary>
    /// 获取数量
    /// </summary>
    /// <returns></returns>
    long CountLong();

    /// <summary>
    /// 获取数量 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    int Count(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 获取数量 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    long CountLong(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 是否存在 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    bool Any(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 获取数量
    /// </summary>
    /// <returns></returns>
    Task<int> CountAsync();

    /// <summary>
    /// 获取数量
    /// </summary>
    /// <returns></returns>
    Task<long> CountLongAsync();

    /// <summary>
    /// 获取数量 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    Task<int> CountAsync(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 获取数量 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    Task<long> CountLongAsync(Expression<Func<T, bool>> expWhere);

    /// <summary>
    /// 是否存在 根据条件
    /// </summary>
    /// <param name="expWhere"></param>
    /// <returns></returns>
    Task<bool> AnyAsync(Expression<Func<T, bool>> expWhere);


    #endregion
}
